package com.ruoyi.lvlian.domain;


import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.annotation.Excel;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 司机信息对象 lv_driver_info
 *
 * @author liyuxi
 * @date 2024-06-06
 */
@Data
@ToString
@ApiModel(value = "司机信息", description = "司机信息")
public class DriverInfo  implements Serializable {
    private static final long serialVersionUID = 1L;

    private String id;
    @ExcelProperty("驾驶证号")
    @ApiModelProperty(value = "驾驶证号")
    @NotNull(message = "驾驶证号不能为空")
    private String licenseNo;

    @ExcelProperty("司机姓名")
    @ApiModelProperty(value = "司机姓名")
    @NotNull(message = "司机姓名不能为空")
    private String name;
    @ExcelProperty("性别")
    @ApiModelProperty(value = "性别")
    private String gender;



    //    @ExcelProperty("检验有效期至")
    @ApiModelProperty(value = "住址")
    private String address;
    @ExcelProperty("司机联系方式")
    @ApiModelProperty(value = "司机联系方式")
//    @NotNull(message = "手机号不能为空")
    private String phoneNo;

    @ExcelProperty("出生日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "出生日期", example = "2020-01-01", dataType = "string")
    private String birthDate;

    @ExcelProperty("初次领证日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "初次领证日期", example = "2020-01-01", dataType = "string")
    private String firstApprovedDate;
    @ExcelProperty("准驾车型")
    @ApiModelProperty(value = "准驾车型")
    private String approvedType;

    @ExcelProperty("驾驶证有效起始日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "驾驶证有效起始日期", example = "2020-01-01", dataType = "string")
    private String startDate;
    @ExcelProperty("驾驶证有效截止日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "驾驶证有效截止日期", example = "2020-01-01", dataType = "string")
    private String endDate;
    //    @ExcelProperty("检验有效期至")
    @ApiModelProperty(value = "驾驶证发证机关")
    private String agency;

    @ApiModelProperty(value = "是否有效 - 0无效, 1有效")
    private String isVariable;

    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "创建时间", example = "2020-01-01", dataType = "string")
    private String createDate;


    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "修改时间", example = "2020-01-01", dataType = "string")
    private String updateDate;

    /**
     * 创建人
     */
    @ApiModelProperty(value = "创建人")
    private String createUser;

    @ExcelProperty("所属公司编码")
    @ApiModelProperty(value = "所属公司编码")
    private String orgCode;


    /**
     *
     */
//    @NotNull(message = "驾驶证正面照片不能为空")
    @Excel(name = "驾驶证正面")
    private String driverLicenseImg;

    /**
     * 驾驶证副业
     */
//    @NotNull(message = "驾驶证附页照片不能为空")
    @Excel(name = "驾驶证附页")
    private String driverLicenseBackImg;

    @ApiModelProperty(value = "司机手机验证码")
    private String smsCode;

    private boolean viewFlag;


    @ApiModelProperty(value = "车辆数量")
    private int vehicleCnt;

    public String getDriverLicenseImg() {
        if (StringUtils.isNotEmpty(driverLicenseImg) && !driverLicenseImg.contains("http")) {
            return "https://data.lvlianhengsheng.com/dev-api/file/fileAttachmentInfo/viewImage?key=" + driverLicenseImg;
        }
        return driverLicenseImg;
    }

    public String getDriverLicenseBackImg() {


        if (StringUtils.isNotEmpty(driverLicenseBackImg) && !driverLicenseBackImg.contains("http")) {
            return "https://data.lvlianhengsheng.com/dev-api/file/fileAttachmentInfo/viewImage?key=" + driverLicenseBackImg;
        }
        return driverLicenseBackImg;
    }

    private String dataStatus;

    @ApiModelProperty(value = "数据来源填 实时物流小程序  四流平台")
    private String dataSource;

    public String getBirthDate() {
        if (licenseNo == null || licenseNo.length() != 18) {
            return birthDate;
        }

        try {
            String birthDateStr = licenseNo.substring(6, 14);

            // 验证日期是否有效
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            sdf.setLenient(false); // 严格模式，验证日期有效性
            Date date = sdf.parse(birthDateStr);

            // 格式化为标准日期格式
            SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
            return outputFormat.format(date);
        } catch (Exception e) {
            return birthDate; // 日期格式无效时返回原值
        }
    }

    public String getStartDate() {
        if(org.apache.commons.lang3.StringUtils.isEmpty( startDate)){
            return null;
        }
        if (org.apache.commons.lang3.StringUtils.isNotEmpty(startDate) && DateUtils.isValidDateTime(startDate)) {
            startDate = startDate.substring(0, 10);
        }
        if (org.apache.commons.lang3.StringUtils.isNotEmpty(startDate)) {
            startDate = DateUtils.unifyDateFormats(startDate);
        }
        return startDate;
    }

    public String getEndDate() {
        if(org.apache.commons.lang3.StringUtils.isEmpty( endDate)){
            return null;
        }
        if (org.apache.commons.lang3.StringUtils.isNotEmpty(endDate) && DateUtils.isValidDateTime(endDate)) {
            endDate = endDate.substring(0, 10);
        }
        if (org.apache.commons.lang3.StringUtils.isNotEmpty(endDate)) {
            endDate = DateUtils.unifyDateFormats(endDate);
        }
        return endDate;
    }

    public String getGender() {
        if (gender==null || "1".equals(gender) ||  gender.contains("男") ) {
            return "男";
        } else  {
            return "女";
        }
    }
}
